package http

import (
	"log"
	"net/http"

	"github.com/gin-gonic/gin"

	"org.knight/biz"
)

type SpecFileHttpHandler struct {
}

// @Summary      spec file upload handler
// @Description  spec file upload handler
// @Tags         spec file handler
// @Produce      json
// @Param        file   param      file  true  "Account ID"
// @Success      200  {object}  string "{"msg": "hello Razeen"}"
// @Failure      400  {object} string "{"msg": "hello Razeen"}"
// @Router       /upload/3gpp/spec [post]
func (s SpecFileHttpHandler) Handle(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "./" + file.Filename
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, dst)

	parser := biz.DocParser{}
	log.Println("try init...")
	parser.Init()
	log.Println("trying to parse")
	parser.Parse(dst)
	log.Println("Done parse")

	c.JSON(http.StatusOK, "success")

}
